/**
 * Created by chen on 2016/8/16.
 */
$(function () {
    $('#cp-upload-face').uploadify({
        uploader: faceUrl,            			            //服务器处理地址
        swf: uploadify_swfUrl,				                    //swf文件地址
        buttonText: "上传头像",                  				//按钮文字
        height: 34,                             				//按钮高度
        width: 82,                              				//按钮宽度
        fileTypeExts: "*.jpg;*.png;*.jpeg;*.gif;",           	//允许的文件类型
        fileTypeDesc: "请选择图片文件",           				//文件说明
        formData: { "imgType": "normal" }, 						//提交给服务器端的参数
        onUploadSuccess: function (file, data, response) {
            var data = $.parseJSON(data);
            if (data.status) {
                //上传成功
                $("#face-img").attr('src',data.url);
            } else {
                //上传失败
                layer.msg(data.msg,{'icon':5,'time':2000});
            }
        }
    });

    //删除图片
    $("._base_cc").delegate("#del_img","click",function(){
        var url = $("#show-imgs").attr('src');
        if (url) {
            layer.confirm('亲,确定要删除该头像?', {icon: 3, title:'提示'}, function(index){
                $.post(delIMGURL,{'url' : url},function(data){
                    if (data.status) {
                        layer.msg(data.msg, {icon: 6,time: 2000});
                        $(".cp-img-defult").show();
                        $(".cp-img-showImg").hide();
                        $("#show-img-name").html('双击上传按钮可上传头像');
                        $("#show-imgs").attr('src','');
                    } else {
                        layer.msg(data.msg, {icon: 5,time: 2000});
                        $(".cp-img-defult").hide();
                        $(".cp-img-showImg").show();
                        $("#show-img-name").html('双击上传按钮可上传头像');
                    }
                },"json");
            });

        }
    });
});